package com.googlecode.imanager.client.util;

import java.io.Serializable;

/**
 * @author wellsantos@wellsantos.com
 * @since 0.01
 */
public class Rectangle implements Serializable {

    private static final long serialVersionUID = 1L;
    
    private int x;
    private int y;    
    private int width;    
    private int height;

    public Rectangle() {
    }

    public Rectangle(int x, int y, int width, int height) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }

    public Rectangle(Point position, Dimension size) {
        this(position.getX(), position.getY(), 
             size.getWidth(), size.getHeight());
    }
    
    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }
    
    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }
    
    public Point getPosition(){
        return new Point(getX(), getY());
    }
    
    public Dimension getSize(){
        return new Dimension(getWidth(), getHeight());
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this){
            return true;
        }
        if (obj instanceof Rectangle){
            Rectangle r = (Rectangle) obj;
            return (r.x == x)
                && (r.y == y)
                && (r.width == width)
                && (r.height == height);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return x ^ (y << 8) ^ (width << 16) ^ (height << 24);
    }

    @Override
    public String toString() {
        return "Rectangle[x=" + x + ", y=" + y + ", width=" + width + ", height=" + height + "]";
    }
        
}
